COMPILER = /usr/local/share/closure-compiler/compiler.jar
CALCDEPS = /usr/local/share/closure-library-read-only/closure/bin/calcdeps.py
PREPLATE = /usr/local/share/prestans/tools/bin/preplate2
GSS_COMPILER = /usr/local/share/closure-compiler/closure-stylesheets.jar
JAVA = java

PROJ_NAME = squiggle
MAIN_JS = AppUI.js

OPT_LEVEL = ADVANCED_OPTIMIZATIONS

deps:
	cd client/; $(CALCDEPS) -o deps -d goog/ -p $(PROJ_NAME) -p prestans/ --output_file=$(PROJ_NAME)-deps.js

docs:
	@echo "writing docs using doxygen"

dist: dist-web
	@echo "build complete! Good luck with the deployment"
    
dist-web: deps css-web-minified
	cd client; $(CALCDEPS) -i $(PROJ_NAME)/ui/web/$(MAIN_JS) -p goog/ -o compiled -c $(COMPILER) -f "--compilation_level=$(OPT_LEVEL)" -f "--externs=../bin/externs/maps/google_maps_api_v3_7.js" -p $(PROJ_NAME) -p prestans/ > ../app/static/app/web/js/$(PROJ_NAME)-web-app.js

css-web-minified:
	cd client/gss/web; for file in `ls *gss`; do filename=$${file%.*}; $(JAVA) -jar $(GSS_COMPILER) --output-renaming-map-format CLOSURE_COMPILED --rename CLOSURE --output-renaming-map ../../$(PROJ_NAME)-$$filename-renaming-map.js --output-file ../../../app/static/site/web/css/$$filename.css $$filename.gss; done

css-web:
	cd client/gss/web; for file in `ls *gss`; do filename=$${file%.*}; $(JAVA) -jar $(GSS_COMPILER) --pretty-print --output-renaming-map-format CLOSURE_UNCOMPILED --output-renaming-map ../../$(PROJ_NAME)-$$filename-renaming-map.js --output-file ../../../app/static/site/web/css/$$filename.css $$filename.gss; done

stubs:
	$(PREPLATE) --prestans-path=app/ --rest-model-path=app/$(PROJ_NAME)/rest/models.py --namespace=$(PROJ_NAME) --output-path=client/$(PROJ_NAME)/data/model

prep:
	ln -s /usr/local/share/closure-library-read-only/closure/goog client/goog
	svn propset svn:externals -F svn-externals .
    
clean:
	rm -f client/$(PROJ_NAME)-deps.js
	rm -f app/static/app/web/js/$(PROJ_NAME)-web-app.js
	@echo "all clear! start re-buidling :)"
